/*
 * @Author: your name
 * @Date: 2021-06-07 21:38:11
 * @LastEditTime: 2022-02-20 13:40:07
 * @LastEditors: Please set LastEditors
 * @Description: 提示显示窗口，特殊窗口，不受interface管理器管理
 * 实现队列显示和立即刷新覆盖显示，按需传参
 * @FilePath: \telescope1080P\src\display_tips.h
 */
#ifndef DISPLAY_TIPS_H
#define DISPLAY_TIPS_H
#include "page_handle.h"
#include "common.h"
#include "common_define.h"
#include <iostream>
#include <list>
#include <mutex>
#define DISPALY_TIPS_PAGE_NAME "display_tips"
class TipsMsg
{
public:
    TipsMsg();
    ~TipsMsg() = default;
    void SetTips(std::string value)
    {
        tips = value;
    }
    std::string GetTips()
    {
        return tips;
    }
    /**
     * @brief Set the Keep Time object
     * 设置停留时间
     * @param time 停留时间，单位ms
     */
    void SetKeepTime(unsigned int time)
    {
        keepTime = time;
    }
    unsigned int GetKeepTime()
    {
        return keepTime;
    }
    void SetTrText(std::string textName)
    {
        trText = textName;
    }
    std::string GetTrText()
    {
        return trText;
    }
    void SetHandleMsg(HandleMessageToPage msg)
    {
        message = msg;
    }
    HandleMessageToPage GetHandleMsg()
    {
        return message;
    }
    void SetType(ConfirmationType type)
    {
        TipsMsg::type = type;
    }
    ConfirmationType GetType()
    {
        return type;
    }

private:
    /**
     * @brief 
     * 消息窗口的字符串，utf-8编码，在无需双语时可使用该参数
     */
    std::string tips;
    /**
     * @brief 
     * 消息窗口的保持时间
     */
    unsigned int keepTime;
    /**
     * @brief 
     * 消息窗口的译文，需要双语时使用该参数
     */
    std::string trText;
    /**
     * @brief 
     * 提示窗口结束提示后回传给界面的消息，例如：蓝牙配对时，超时提示信息结束后告诉界面已经超时
     */
    HandleMessageToPage message;
    /**
     * @brief 
     * 确认框类型
     */
    ConfirmationType type;
};
class DisplayTips : public ConfirmTips
{
public:
    DisplayTips();
    ~DisplayTips() = default;
    static DisplayTips &GetInstance();
    /**
     * @brief 
     * 
     * @param tips 
     * @param immediately 是否立即覆盖当前内容显示，默认为true
     */
    void Display(TipsMsg tips, bool immediately = true);
    void AddTips(TipsMsg tips);
    void OpenDisplayTipsPage(TipsMsg initTips, bool immediately);
    void SetPage(PageHandle *window);
    bool GetOneTips(TipsMsg &tips);
    PageHandle *GetPage();
    void TipsDisplaying();
    void StopDisplay();
    void TipsDisplayingSetText(void *ctx);
    void StopDisplayingClosePage();
    /**
     * @brief 
     * 刷新覆盖当前内容
     */
    void TipsDisplayingRightNow(TipsMsg tips);
    /**
     * @brief 
     * 强制中断提示窗口，由外部业务调用
     */
    void ForceStopDisplay();
    /**
     * @brief 
     * 设置界面保存配置信息结果提示
     * @param ret true-保存成功，false-保存失败
     */
    void SaveConfiguration(bool ret);
    void DisplayNameNotEmpty();
    void ValueInvalid();

private:
    std::mutex m_mutex;
    std::list<TipsMsg> tipsQueue;
    std::unique_ptr<PageHandle> page;
    /**
     * @brief 
     * keepTime 当前内容的停留时间，用于覆盖刷新时重置停留时间
     */
    unsigned int keepTime;
    unsigned int sleepTime;
    bool keepWorking;
};
#endif